// Copyright (C) 2011 YANG Hao (yangh2007@gmail.com). All rights reserved.
//
// This file is part of the (cute)octopus project.
//
// This file may be distributed and/or modified under the terms of the
// GNU General Public License version 2 as published by the Free Software
// Foundation.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Author(s): YANG Hao


#include "ocreator.h"

#include "oaction.h"
#include "odoc.h"
#include "otask.h"
#include "odescriptors.h"

OCreator::OCreator(const QList<ODocDescriptor*>& fs, const QList<OAction*>& actions)
{
	Q_ASSERT(!fs.empty());
	foreach(ODocDescriptor* f, fs){
		m_formatList.append(f);
		foreach(QString s, f->suffices())
			m_formatMap.insert(s, f);
	}
	for(int i = 0; i < m_formatList.size(); i++)
		m_filters.append(m_formatList[i]->filter()).append(";;");
	m_filters.append("All files (*.*)");

	m_actions = actions;
	foreach(OAction* a, actions){
		if(!m_menuNames.contains(a->menuName()))
			m_menuNames.append(a->menuName());
		if(!m_toolBarNames.contains(a->toolBarName()))
			m_toolBarNames.append(a->toolBarName());
	}
}

OCreator::~OCreator(){qDeleteAll(m_formatList);}

QVariant OCreator::tryProperty(const char* name, const QVariant& v)
{
	if(QObject::dynamicPropertyNames().contains(name))
		return property(name);
	setProperty(name, v);
	return v;
}